<html>
<head><meta charset="utf-8"><title>Warn on unused places? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Warn.20on.20unused.20places.3F.html">Warn on unused places?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221715040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Warn%20on%20unused%20places%3F/near/221715040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Warn.20on.20unused.20places.3F.html#221715040">(Jan 05 2021 at 23:18)</a>:</h4>
<p>These two (silly) functions do very different things:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">demo1</span><span class="p">(</span><span class="n">x</span>: <span class="p">(</span><span class="nb">String</span><span class="p">,))</span><span class="w"> </span>-&gt; <span class="nb">String</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="p">.</span><span class="mi">0</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">demo2</span><span class="p">(</span><span class="n">x</span>: <span class="p">(</span><span class="nb">String</span><span class="p">,))</span><span class="w"> </span>-&gt; <span class="nb">String</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="p">.</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="p">.</span><span class="mi">0</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>We probably can't change them to have the same semantics (since it could change drop order for some code), but maybe it would be worth warning about the latter?</p>
<p>Currently this code is warning-free:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">demo3</span><span class="p">(</span><span class="n">x</span>: <span class="p">(</span><span class="nb">String</span><span class="p">,))</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="p">.</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I would propose that we add a new lint for that, suggesting that it be replaced with <code>drop(x.0);</code> (or just removed, if <code>Copy</code>).  Strawman names, <code>unused_place</code> or <code>place_statement</code> or <span aria-label="bike" class="emoji emoji-1f6b2" role="img" title="bike">:bike:</span><span aria-label="house" class="emoji emoji-1f3e0" role="img" title="house">:house:</span>.</p>
<p>Thoughts?</p>



<a name="221715469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Warn%20on%20unused%20places%3F/near/221715469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Poliorcetics <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Warn.20on.20unused.20places.3F.html#221715469">(Jan 05 2021 at 23:22)</a>:</h4>
<p>While I have no idea for good names, I like the idea of such a warning</p>



<a name="221719075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Warn%20on%20unused%20places%3F/near/221719075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Warn.20on.20unused.20places.3F.html#221719075">(Jan 06 2021 at 00:03)</a>:</h4>
<p>also see<br>
<a href="https://github.com/rust-lang/rust/issues/79735">https://github.com/rust-lang/rust/issues/79735</a><br>
<a href="https://github.com/rust-lang/rust/issues/80059">https://github.com/rust-lang/rust/issues/80059</a><br>
<a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/261">https://github.com/rust-lang/unsafe-code-guidelines/issues/261</a></p>



<a name="221726623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Warn%20on%20unused%20places%3F/near/221726623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Warn.20on.20unused.20places.3F.html#221726623">(Jan 06 2021 at 02:14)</a>:</h4>
<p>(Yeah, I probably should have mentioned those.  They're what had me thinking about this.)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>